package com.itheima.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.itheima.bean.Student;
import com.itheima.service.StudentService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@RestController
@RequestMapping("/student")
public class StudentController{
    @Autowired
    private StudentService studentService;

    /**
     * 处理分页查询的请求
     */
    @RequestMapping("/selectByPage")
    protected PageInfo<Student> selectByPage(Integer currentPage,Integer pageSize) {
       return studentService.selectByPage(currentPage, pageSize);
    }

    /**
      * 处理添加学生的请求
     */
    @RequestMapping("/addStudent")
    protected int addStudent(Student student){
        return studentService.addStudent(student);
    }

    /**
     * 处理修改学生的请求
     */
    @RequestMapping("/updateStudent")
    protected int updateStudent(Student student){
        return studentService.updateStudent(student);
    }

    /**
     * 处理删除学生的请求
     */
    @RequestMapping("/deleteStudent")
    protected int deleteStudent(String number ){
        return studentService.deleteStudent(number);
    }

}
